package com.twang.stock.config;

import com.twang.stock.email.EmailWranSendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.UnknownHostException;

/**
 * 生产者:direct.stock.queu
 */
@Service
@Slf4j
public class StockMsgSender {

    @Autowired
    private EmailWranSendService emailWranSendService;

    /**
     * 分钟
     * @param message
     */
    public void sendMessage(String message) {
        log.info("=====================》 Sent 分时消息,code={} {}",message);

        //rabbitTemplate.convertAndSend(directExchange.getName(), RabbitMQConfiguration.DIRECT_ROUTING_KEY, message);
        try {
            emailWranSendService.receiveMessage(message);
        } catch (UnknownHostException e) {
            log.error("=====================》 sendMessage Sent 分时消息,ERROR:{}",e);
        }
    }

    /**
     * Email
     * @param message
     */
    public void sendEmailMessage(String message) {
        log.info("=====================》 Sent 分时消息,code={} {}",message);
        // rabbitTemplate.convertAndSend(RabbitMQConfiguration.EXCHANGE_NAME_EMAIL_DIRECT, RabbitMQConfiguration.EMAIL_WARN_ROUTING_KEY, message);
        try {
            emailWranSendService.receiveMessage(message);
        } catch (UnknownHostException e) {
            log.info("=====================》 sendEmailMessage Sent 分时消息,ERROR:{}",e);
        }
    }
}
